
/**
 * This program demonstrate exporting pdf file with japanese fonts.
 * Use iTextAsian.jar library to add Asian fonts, ex: HeiseiMin-W3.
 * In oder to run this program
 * + install MS Mincho font into Windows.
 * + version of iTextAsian must be 1.5.2 or less than. The 5.0 is not appropriate
 * @author Dang Nhu Tuan
 */

package japanese;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

public class PdfExporter {

    private static PropertiesConfiguration config;

    static {
        try {
            config = new PropertiesConfiguration("config.properties");
        } catch (ConfigurationException ex) {
            ex.printStackTrace();
            System.exit(1);
        }
    }

    public static void main(String[] args) {
        try {
            JasperReport jr = JasperCompileManager.compileReport(config.getString("report.jrxml.path"));
            JasperPrint jp = JasperFillManager.fillReport(jr, null, getConnection());
            JasperExportManager.exportReportToPdfFile(jp, config.getString("report.pdf.output"));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException, ClassNotFoundException {
        Class.forName(config.getString("jdbc.driver.class"));
        return DriverManager.getConnection(config.getString("jdbc.url"));
    }
}
